package com.front.teacher.teacherapp.base;

import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.front.teacher.teacherapp.R;
import com.front.teacher.teacherapp.utils.SystemBarTintManager;

import butterknife.ButterKnife;

/**
 */
public abstract class BaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setTranslucentStatus(true);
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintResource(R.color.mainGreen);//通知栏所需颜色
        }
        if (savedInstanceState == null){
            setContentView(getLayoutId());
            ButterKnife.inject(this);
            init();
        }
    }

    public final void init() {
        initView();
        initData();
    }

    public void initData() {

    }


    public abstract void initView();

    public abstract int getLayoutId();

    @TargetApi(19)
    private void setTranslucentStatus(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }

    public void showDialog(String str) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setMessage(str);
        dialog.setNegativeButton("真的", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        dialog.setPositiveButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        dialog.show();
    }

    public  void toastShow(String str){
        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
    }
}
